const { checkRole } = require("../middleware/role")
const { checkTokenAdmin } = require("../middleware/jwt")
const role = require("../controllers/role")
module.exports = app => {
    // 权限管理 需要注册中间件
    app.use("/admin/role", checkTokenAdmin)
    // 这些都需要权限
    app.use("/admin/role", (req, res, next) => checkRole(req, res, next, "permission"))
    app.get("/admin/role", role.test)

    // 查询菜单
    app.get("/admin/role/menu", role.getAllMenu)
    app.post("/admin/role/menu", role.createMenu)
    app.put("/admin/role/menu/:id", role.updateMenu)
    app.delete("/admin/role/menu/:id", role.deleteMenu)
    // 查询角色
    app.get("/admin/role/role", role.getAllRole)
    app.post("/admin/role/role", role.createRole)
    app.put("/admin/role/role/:id", role.updateRole)
    app.delete("/admin/role/role/:id", role.deleteRole)
    // 查询用户
    app.get("/admin/role/user", role.getAllUser)
    app.post("/admin/role/user", role.createUser)
    app.put("/admin/role/user/:id", role.updateUser)
    app.delete("/admin/role/user/:id", role.deteleUser)
    // 查询用户角色
    app.get("/admin/role/user_role/:id", role.getUserRoleList)
    // 查询角色权限
    app.get("/admin/role/role_menu/:id", role.getRoleMenu)
    // 查询用户权限
    app.get("/admin/role/user_menu/:id", role.getUserRole)
}